package com.dao.qsl;

import com.bean.qsl.BxInfo;
import com.util.qsl.Dbutil;
import org.springframework.stereotype.Repository;

import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class BxChaXun {
      public  List<BxInfo> cx(String zt, HttpServletRequest request){
	  Dbutil d=new Dbutil();
	  Connection c=null;

	  List<BxInfo> list=new ArrayList<>();

	  Map<String,Object> user = (Map<String,Object>)request.getSession().getAttribute("user");
	  String ename = (String) user.get("Hname");
	  try {
	        c=d.getConnection();
	        String sql="SELECT m.*,h.Hname from household h, maintain m where m.aid=h.aid and maintain_status=? and  h.Hname=?";
	        PreparedStatement pr=c.prepareStatement(sql);
	        pr.setString(1,zt);
	        pr.setString(2,ename);

	        ResultSet rs=pr.executeQuery();

	        while (rs.next()) {
		    BxInfo b=new BxInfo();
		    b.setDdxh(rs.getInt("maintain_id"));
		    b.setZhxm(rs.getString("Hname"));
		    b.setBxlr(rs.getString("maintain_content"));
		    b.setTbxq(rs.getString("tpdz"));
		    b.setSqrq(rs.getString("maintain_date"));
		    b.setLxdh(rs.getString("maintain_phone"));
		    b.setClzt(rs.getString("maintain_status"));
		    b.setPf(rs.getString("maintain_appraise"));

		    list.add(b);
	        }

	  }catch(Exception e){
	        e.printStackTrace();
	  }
	  return list;
      }
}
